package com.ruoyi.project.module.keshi.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.keshi.domain.Keshi;
import com.ruoyi.project.module.keshi.service.IKeshiService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 科室 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-12-27
 */
@Controller
@RequestMapping("/module/keshi")
public class KeshiController extends BaseController
{
    private String prefix = "module/keshi";
	
	@Autowired
	private IKeshiService keshiService;
	
	@RequiresPermissions("module:keshi:view")
	@GetMapping()
	public String keshi()
	{
	    return prefix + "/keshi";
	}
	
	/**
	 * 查询科室列表
	 */
	@RequiresPermissions("module:keshi:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Keshi keshi)
	{
		startPage();
        List<Keshi> list = keshiService.selectKeshiList(keshi);
		return getDataTable(list);
	}
	
	/**
	 * 新增科室
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存科室
	 */
	@RequiresPermissions("module:keshi:add")
	@Log(title = "科室", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Keshi keshi)
	{		
		return toAjax(keshiService.insertKeshi(keshi));
	}

	/**
	 * 修改科室
	 */
	@GetMapping("/edit/{keshiId}")
	public String edit(@PathVariable("keshiId") Integer keshiId, ModelMap mmap)
	{
		Keshi keshi = keshiService.selectKeshiById(keshiId);
		mmap.put("keshi", keshi);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存科室
	 */
	@RequiresPermissions("module:keshi:edit")
	@Log(title = "科室", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Keshi keshi)
	{		
		return toAjax(keshiService.updateKeshi(keshi));
	}
	
	/**
	 * 删除科室
	 */
	@RequiresPermissions("module:keshi:remove")
	@Log(title = "科室", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(keshiService.deleteKeshiByIds(ids));
	}
	
}
